package justcents.game.sticks;

import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class EscolhaPalpiteActivity extends Activity {

	@Override
	public void onCreate(Bundle icicle){
		super.onCreate(icicle);
		setContentView(R.layout.escolhapalpite);
		
		final Button btPalpitesOk 	= (Button) findViewById(R.id.btPalpiteOk);
		final RadioGroup rgPalpites	= (RadioGroup) findViewById(R.id.rgEscolhaPalpite);

		//Array Lista de Radio Button da Tela
		ArrayList<RadioButton> arRadioButton = new ArrayList<RadioButton>();
		
		arRadioButton.add((RadioButton) findViewById(R.id.rbPalpite0));
		arRadioButton.add((RadioButton) findViewById(R.id.rbPalpite1));
		arRadioButton.add((RadioButton) findViewById(R.id.rbPalpite2));
		arRadioButton.add((RadioButton) findViewById(R.id.rbPalpite3));
		arRadioButton.add((RadioButton) findViewById(R.id.rbPalpite4));
		arRadioButton.add((RadioButton) findViewById(R.id.rbPalpite5));
		arRadioButton.add((RadioButton) findViewById(R.id.rbPalpite6));
		arRadioButton.add((RadioButton) findViewById(R.id.rbPalpite7));
		arRadioButton.add((RadioButton) findViewById(R.id.rbPalpite8));
		arRadioButton.add((RadioButton) findViewById(R.id.rbPalpite9));
		arRadioButton.add((RadioButton) findViewById(R.id.rbPalpite10));
		arRadioButton.add((RadioButton) findViewById(R.id.rbPalpite11));
		arRadioButton.add((RadioButton) findViewById(R.id.rbPalpite12));
		
		//Pegando o parametro passado pela PartidaOffline
		Intent it = getIntent();
		if(it != null){
			Bundle params = it.getExtras();
			if(params != null){
				int nrTotalPalitosNaMesa = params.getInt("nrTotalPalitosNaMesa");
				ArrayList<Integer> arNumerosEscolhidos = new ArrayList<Integer>();
				arNumerosEscolhidos = params.getIntegerArrayList("arNumerosEscolhidos");
				
				for (int i = 0; i <= nrTotalPalitosNaMesa; i++) {
					RadioButton rbDesabilitado = (RadioButton) arRadioButton.get(i);
					rbDesabilitado.setVisibility(1);
					
					
					for(int b = 0; b < arNumerosEscolhidos.size(); b++){
						if(arNumerosEscolhidos.get(b) == i){
							RadioButton rbBloqueado = (RadioButton) arRadioButton.get(i);
							rbBloqueado.setClickable(false);
							rbBloqueado.setTextColor(Color.RED);
						}
					}
					
				}
				
			}
		}
		
		//Click do Botão
        btPalpitesOk.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				int checkedId = rgPalpites.getCheckedRadioButtonId();
				int nrPalpite = 0;
				switch (checkedId) {
					case R.id.rbPalpite1:
						nrPalpite = 1;
						break;
					case R.id.rbPalpite2:
						nrPalpite = 2;
						break;
					case R.id.rbPalpite3:
						nrPalpite = 3;
						break;
					case R.id.rbPalpite4:
						nrPalpite = 4;
						break;
					case R.id.rbPalpite5:
						nrPalpite = 5;
						break;
					case R.id.rbPalpite6:
						nrPalpite = 6;
						break;
					case R.id.rbPalpite7:
						nrPalpite = 7;
						break;
					case R.id.rbPalpite8:
						nrPalpite = 8;
						break;
					case R.id.rbPalpite9:
						nrPalpite = 9;
						break;
					case R.id.rbPalpite10:
						nrPalpite = 10;
						break;
					case R.id.rbPalpite11:
						nrPalpite = 11;
						break;
					case R.id.rbPalpite12:
						nrPalpite = 12;
						break;
					default:
						break;
				}
				Intent data = new Intent();
				data.putExtra("nrPalpite", nrPalpite);
				setResult(2, data);
				finish();
			}
		});
	}
}
